/*
 * @Description: 模拟获取菜单数据
 * @Author: 0001100986/LiuShuai
 * @Date: 2021-06-22 14:09:49
 * @LastEditTime: 2021-10-18 11:19:04
 * @LastEditors: 0001100986/LiuShuai
 */

import store from '../store';
import router from '../router';
import { allRoutes } from '@/router/index.js';
import { routerMatch } from '@/utils/menu.js';
import { menuData } from '@/mock/menuData.js';

export function getMenuList () {
  let sys = JSON.parse(localStorage.getItem('sys'));
  let isLogin = false;

  if (sys) {
    isLogin = sys.user.isLogin;
  }

  if (!isLogin) {
    return;
  }

  routerMatch(menuData, allRoutes).then(routes => {
    let role = sys.user.info.roleUserlabel;
    // 角色权限区分菜单
    if (role === '超级管理员') {
      menuData[6].children = [
        {
          id: 701,
          title: '个人中心',
          title_en: 'Personal settings',
          path: '/user/personal-settings',
          noMenu: true
        },
        // {
        //   id: 702,
        //   title: '账户规则',
        //   title_en: 'Account rule',
        //   path: '/user/account-rule'
        // },
        {
          id: 703,
          title: '账户管理',
          title_en: 'Account manage',
          path: '/user/account-manage'
        },
        {
          id: 704,
          title: '租户管理',
          title_en: 'Tenant manage',
          path: '/user/tenant-manage'
        },
        // {
        //   id: 705,
        //   title: '历史记录',
        //   title_en: 'User operations',
        //   path: '/user/operations'
        // }
      ];
      menuData[7].children = [
        {
          id: 801,
          title: '邮件服务器',
          title_en: 'Email server',
          path: '/system/email-server'
        },
        {
          id: 802,
          title: '网元备份',
          title_en: 'Ne backups',
          path: '/system/ne-backups'
        },
        {
          id: 803,
          title: '数据库备份',
          title_en: 'Database backups',
          path: '/system/database-backups'
        },
        {
          id: 804,
          title: '数据库恢复',
          title_en: 'Database recovery',
          path: '/system/database-recovery'
        },
        {
          id: 805,
          title: '系统参数',
          title_en: 'System Parameter',
          path: '/system/parameter'
        },
        {
          id: 806,
          title: '系统日志',
          title_en: 'System logs',
          path: '/system/logs'
        },
        {
          id: 807,
          title: '关于IONE',
          title_en: 'About ione',
          path: '/system/about-ione'
        }
      ];
    }
    if (role === '系统管理员') {
      menuData[6].children = [
        {
          id: 701,
          title: '个人中心',
          title_en: 'Personal settings',
          path: '/user/personal-settings',
          noMenu: true
        },
        {
          id: 702,
          title: '账户管理',
          title_en: 'Account manage',
          path: '/user/account-manage'
        },
        {
          id: 703,
          title: '租户管理',
          title_en: 'Tenant manage',
          path: '/user/tenant-manage'
        },
        // {
        //   id: 704,
        //   title: '历史记录',
        //   title_en: 'User operations',
        //   path: '/user/operations'
        // }
      ];
      menuData[7].children = [{
        id: 801,
        title: '邮件服务器',
        title_en: 'Email server',
        path: '/system/email-server'
      },
      {
        id: 802,
        title: '网元备份',
        title_en: 'Ne backups',
        path: '/system/ne-backups'
      },
      {
        id: 803,
        title: '数据库备份',
        title_en: 'Database backups',
        path: '/system/database-backups'
      },
      {
        id: 804,
        title: '系统参数',
        title_en: 'System Parameter',
        path: '/system/parameter'
      },
      {
        id: 805,
        title: '关于IONE',
        title_en: 'About ione',
        path: '/system/about-ione'
      }];
    }
    if (role === '系统维护员') {
      menuData[6].children = [
        {
          id: 701,
          title: '个人中心',
          title_en: 'Personal settings',
          path: '/user/personal-settings',
          noMenu: true
        },
        {
          id: 702,
          title: '账户管理',
          title_en: 'Account manage',
          path: '/user/account-manage'
        },
        {
          id: 703,
          title: '租户管理',
          title_en: 'Tenant manage',
          path: '/user/tenant-manage'
        },
        // {
        //   id: 704,
        //   title: '历史记录',
        //   title_en: 'User operations',
        //   path: '/user/operations'
        // }
      ];
      menuData[7].children = [{
        id: 801,
        title: '邮件服务器',
        title_en: 'Email server',
        path: '/system/email-server'
      },
      {
        id: 802,
        title: '系统参数',
        title_en: 'System Parameter',
        path: '/system/parameter'
      },
      {
        id: 803,
        title: '关于IONE',
        title_en: 'About ione',
        path: '/system/about-ione'
      }];
    }
    store.dispatch('menu/setMenuList', menuData);
    router.options.routes = Array.from(
      new Set(router.options.routes.concat(routes))
    );
    router.addRoutes(routes); // 动态添加路由
  });
}

